Completed
Push — master ( bbd6f2...66200a )
by Dongxin
26s
created

options.js ➔ setPreviewColor   B

Complexity

Conditions 1
Paths 128

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 128
nop 1
dl 0
loc 12
rs 8.8571
1
//////////////////////////////////////////////////////////////////////////////////////
2
// Copyright © 2017 TangDongxin
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining
5
// a copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
//////////////////////////////////////////////////////////////////////////////////////
22
23
function setPreviewColor(result) {
24
    console.log("load Color");
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
25
    document.getElementById("fontLabel").style.fontFamily        = result.fontStyle    || "Consolas";
26
27
    document.querySelector("#bgColorLabel").style.backgroundColor = result.bgColor      || "#FDF6E3";
28
    document.querySelector("#intColorLabel").style.color          = result.intColor     || "#657A81";
29
    document.querySelector("#strColorLabel").style.color          = result.strColor     || "#2AA198";
30
    document.querySelector("#keyColorLabel").style.color          = result.keyColor     || "#B58900";
31
    document.querySelector("#defaultColorLabel").style.color      = result.defaultColor || "#586E75";
32
33
    document.querySelector("#strictOnly").checked = result.strictOnly   || false;
34
}
35
36
function onError(error) {
37
    console.log(`Error: ${error}`);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
38
}
39
40
function saveOptions(e) {
41
    e.preventDefault();
42
    browser.storage.local.set({
0 ignored issues
show
Bug introduced by
The variable browser seems to be never declared. If this is a global, consider adding a /** global: browser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
43
        bgColor:      document.querySelector("#bgColor").value,
44
        intColor:     document.querySelector("#intColor").value,
45
        strColor:     document.querySelector("#strColor").value,
46
        keyColor:     document.querySelector("#keyColor").value,
47
        defaultColor: document.querySelector("#defaultColor").value,
48
        fontStyle:    document.querySelector("#fontStyle").value,
49
50
        strictOnly:   document.querySelector("#strictOnly").checked
51
52
    });
53
    alert("Success");
54
    browser.storage.local.get().then(setCurrentChoice, onError);
55
}
56
57
function setCurrentChoice(result) {
58
    console.log(result);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
59
    document.querySelector("#bgColor").value      = result.bgColor      || "#FDF6E3";
60
    document.querySelector("#intColor").value     = result.intColor     || "#657A81";
61
    document.querySelector("#strColor").value     = result.strColor     || "#2AA198";
62
    document.querySelector("#keyColor").value     = result.keyColor     || "#B58900";
63
    document.querySelector("#defaultColor").value = result.defaultColor || "#586E75";
64
    document.querySelector("#fontStyle").value    = result.fontStyle    || "Consolas";
65
66
    document.querySelector("#strictOnly").checked = result.strictOnly   || false;
67
68
    setPreviewColor(result);
69
}
70
71
function restoreOptions() {
72
    browser.storage.local.get().then(setCurrentChoice, onError);
0 ignored issues
show
Bug introduced by
The variable browser seems to be never declared. If this is a global, consider adding a /** global: browser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
73
}
74
75
document.addEventListener("DOMContentLoaded", restoreOptions);
76
document.querySelector("form").addEventListener("submit", saveOptions);
77